<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        window.addEventListener('load',function(){
            var btn = document.querySelector('button');
            //首先，设置一个计时器 setTimeout(函数/函数名,定时时间‘毫秒计数’)
            //写法一
            // var timer = setTimeout(function(){
            //     console.log('爆炸了')
            // },3000)
            //写法二
            function callback(){
                console.log('爆炸了')
            }
            var timer = setTimeout(callback,3000)
            btn.addEventListener('click',function(){
                clearTimeout(timer)
            })
        })
    </script>
    <button>点击停止计时器</button>
</body>
</html>